//
//  JSMDreamCityPrefectureDetailTableViewCell.m
//  TakeYouTourTogether
//
//  Created by king on 15/12/3.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMDreamCityPrefectureDetailTableViewCell.h"

@implementation JSMDreamCityPrefectureDetailTableViewCell

#pragma mark - Method 自定义初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createTableViewCell];
    }
    return self;
}
#pragma mark - Method createTableViewCell
- (void)createTableViewCell {
    
    self.mainImageView = [[BaseImageView alloc] init];
    [self.contentView addSubview:self.mainImageView];
        self.mainImageView.backgroundColor = [UIColor clearColor];
    self.mainImageView.layer.masksToBounds = YES;
    self.mainImageView.layer.cornerRadius = 5;
    self.titleLabel = [[BaseLabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    
    self.allTextLabel = [[BaseLabel alloc] init];
    [self.contentView addSubview:self.allTextLabel];
    self.allTextLabel.backgroundColor = [UIColor clearColor];
    self.allTextLabel.textAlignment = NSTextAlignmentRight;
    self.allTextLabel.font = [UIFont systemFontOfSize:14];
    self.allTextLabel.textColor = [UIColor colorWithRed:0.000 green:0.130 blue:1.000 alpha:1.000];
    
    self.infoLabel = [[BaseLabel alloc] init];
    [self.contentView addSubview:self.infoLabel];
    self.infoLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.infoLabel.numberOfLines = 0;
    self.infoLabel.font = [UIFont systemFontOfSize:16];
    
    self.contentView.layer.borderWidth = 2;
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.borderColor =  [UIColor colorWithRed:0.839 green:0.855 blue:0.757 alpha:1.000].CGColor;
}
#pragma mark - Method layoutSubviews
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).with.insets(UIEdgeInsetsMake(5, 5, 5, 5));
    }];
    [self.mainImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX);
        make.width.equalTo(self.contentView.mas_width);
        make.top.equalTo(self.contentView.mas_top);
        make.height.mas_equalTo(200*ALL_EDITION_HEIGHT);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mainImageView.mas_bottom);
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.right.equalTo (self.allTextLabel.mas_left);
        make.height.mas_equalTo(40*ALL_EDITION_HEIGHT);
    }];
    [self.allTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mainImageView.mas_bottom);
        make.left.equalTo(self.titleLabel.mas_right);
        make.right.equalTo (self.contentView.mas_right).offset(-10);
        make.width.mas_equalTo(65);
        make.height.mas_equalTo(40*ALL_EDITION_HEIGHT);
    }];
}
#pragma mark - Method setTempModel:
- (void)setTempModel:(JSMDreamCityPrecialTrailsDetailModel *)tempModel {
    if (_tempModel != tempModel) {
        _tempModel = tempModel;
    }
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:tempModel.cover] placeholderImage:[UIImage imageNamed:PLACE_HOLDER_IMAGE]];
    NSString *title = [NSString stringWithFormat:@"%@ %@", tempModel.destination, tempModel.name];
    self.titleLabel.text = title;
    self.allTextLabel.text = @"查看全文";
    self.infoLabel.text = tempModel.mydescription;
    [self.infoLabel sizeToFit];
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil];
    CGRect rect = [self.infoLabel.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    [self.infoLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom);
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo (self.mas_right).offset(-15);
        make.height.mas_equalTo(rect.size.height);
    }];
}

@end
